/*
 * SiblingIterator.java
 *
 * Created on July 31, 2004, 12:49 PM
 */

package org.infoset.xml.util;

import java.util.*;

import org.infoset.xml.*;

/**
 *
 * @author  alex
 */
public class SiblingIterator implements Iterator<Child> {
   
   Child sibling;
   boolean forward;
   
   /** Creates a new instance of SiblingIterator */
   public SiblingIterator(Child sibling,boolean forward) {
      this.sibling = sibling;
      this.forward = forward;
   }
   
   public boolean hasNext() {
      return sibling!=null;
   }
   
   public Child next() {
      Child toReturn = sibling;
      sibling = forward ? sibling.getFollowingSibling() : sibling.getPrecedingSibling();
      return toReturn;
   }
   
   public void remove() {
      throw new UnsupportedOperationException("Child cannot be removed through iterator.");
   }
   
}
